package org.jivesoftware.webchat.servlets;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.infoview.db.DbUtil;

/**
 * 
 */
public class AdvertisementServlet extends HttpServlet implements Servlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public AdvertisementServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		final String city = request.getParameter("city");
		String photo = "http://";
		try {
			Connection conn = DbUtil.getConnection();

			String sql = "select photo from offlack where city = ?";
		      
			PreparedStatement pstmt = conn.prepareStatement(sql);

			pstmt.setString(1, city);

			ResultSet rs = pstmt.executeQuery();  //获得查询结果
			
			photo = rs.getString("photo");

			pstmt.close();
			conn.close();

		} catch (SQLException e) {
			e.printStackTrace();
		}
		// response.getWriter().println("<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><script type=\"text/javascript\">showTranscriptWindow(null);</script></head><body></body></html>");
//		response.sendRedirect("transcriptmain.jsp?workgroup=" + workgroup
//				+ "&chatID=" + chatID);
		response.getWriter().print(photo);
	}

	public void init() throws ServletException {
		super.init();
	}
}